/******/ var __webpack_modules__ = ([
/* 0 */,
/* 1 */
/***/ (function() {


var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
if (window.plus) {
    plusReady();
}
else {
    document.addEventListener("plusready", plusReady, false);
}
var runQueue = new Map();
var threadPool = new Map();
var workerUrl = [];
var messageQueue = new Map();
function plusReady() {
    if (window.Worker) {
        while (workerUrl.length) {
            var worker = workerUrl.shift();
            if (worker)
                create(worker.id, worker.url, worker.max);
        }
    }
}
function create(id, url, max) {
    var _this = this;
    if (window.plus) {
        plus.io.resolveLocalFileSystemURL(url, function (entry) {
            entry.file(function (file) {
                var reader = new plus.io.FileReader();
                reader.readAsText(file);
                reader.onloadend = function (e) {
                    var _a;
                    var baseUrl = "file://" + plus.io.convertLocalFileSystemURL("/");
                    baseUrl = baseUrl.substring(0, baseUrl.length - 1);
                    var workerCode = "\n          var newImportScripts = self.importScripts;\n          self.importScripts = function(arguments) {\n            var isHttps = ".concat(/^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9_-](\?)?)*)*$/i.toString(), ";\n            if(typeof arguments === \"string\") {\n              if(!isHttps.test(arguments)) {\n                arguments = \"").concat(baseUrl, "\" + arguments\n              }\n              newImportScripts(arguments)\n            } else {\n              for(var i = 0; i < arguments.length; i++) {\n                  if(typeof arguments[i] === \"string\") {\n                    if(!isHttps.test(arguments[i])) {\n                      arguments[i] = \"").concat(baseUrl, "\" + arguments[i]\n                    }\n                    newImportScripts(arguments[i])\n                  }\n              }\n            }\n          };\n          ").concat((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.result, "\n          ");
                    var workerList = [];
                    for (var index = 0; index < max; index++) {
                        var worker = new Worker(URL.createObjectURL(new Blob([workerCode], { type: "text/javascript" })));
                        worker.addEventListener("message", function (event) { return __awaiter(_this, void 0, void 0, function () {
                            var runWorker;
                            var _a, _b;
                            return __generator(this, function (_c) {
                                runWorker = (_a = runQueue.get(id)) === null || _a === void 0 ? void 0 : _a.shift();
                                runWorker && ((_b = threadPool.get(id)) === null || _b === void 0 ? void 0 : _b.push(runWorker));
                                sendMessage(id, stringifyWebview(event.data));
                                return [2 /*return*/];
                            });
                        }); });
                        workerList.push(worker);
                    }
                    runQueue.set(id, []);
                    threadPool.set(id, workerList);
                    if (messageQueue.has(id)) {
                        var queue = messageQueue.get(id);
                        while (queue === null || queue === void 0 ? void 0 : queue.length) {
                            var message = queue.shift();
                            if (message && id === message.id)
                                postWorkerMessage(id, message.data);
                        }
                    }
                };
            });
        });
    }
    else {
        workerUrl.push({ id: id, url: url, max: max });
    }
}
function sendMessage(id, message) {
    if (plus.webview.getWebviewById("__uniapp__service")) {
        plus.webview.postMessageToUniNView({
            id: id,
            type: "UniWorker",
            args: message,
        }, "__uniapp__service");
    }
}
function postWorkerMessage(id, message) {
    var _a, _b, _c, _d;
    var worker = ((_a = threadPool.get(id)) === null || _a === void 0 ? void 0 : _a.shift()) || ((_b = runQueue.get(id)) === null || _b === void 0 ? void 0 : _b.shift());
    if (worker) {
        var list = [];
        message = parseWebview(message, list);
        worker.postMessage(message, list);
        (_c = runQueue.get(id)) === null || _c === void 0 ? void 0 : _c.push(worker);
    }
    else {
        if (!messageQueue.has(id)) {
            messageQueue.set(id, []);
        }
        (_d = messageQueue.get(id)) === null || _d === void 0 ? void 0 : _d.push({ id: id, data: message });
    }
}
function terminate(id) {
    var _a;
    (_a = threadPool.get(id)) === null || _a === void 0 ? void 0 : _a.forEach(function (worker) {
        worker === null || worker === void 0 ? void 0 : worker.terminate();
    });
    runQueue.delete(id);
    threadPool.delete(id);
    messageQueue.delete(id);
}
window.create = create;
window.terminate = terminate;
window.postWorkerMessage = postWorkerMessage;
function stringifyWebview(data) {
    if (typeof data === "object") {
        return JSON.stringify(data, function (key, value) {
            if (value instanceof ArrayBuffer) {
                return {
                    type: "ArrayBuffer",
                    value: Array.prototype.slice.call(new Uint8Array(value)),
                };
            }
            else if (value instanceof Uint8Array) {
                return {
                    type: "Uint8Array",
                    value: Array.prototype.slice.call(value),
                };
            }
            else if (value instanceof Int8Array) {
                return {
                    type: "Int8Array",
                    value: Array.prototype.slice.call(value),
                };
            }
            else if (value instanceof Int16Array) {
                return {
                    type: "Int16Array",
                    value: Array.prototype.slice.call(value),
                };
            }
            else if (value instanceof Int32Array) {
                return {
                    type: "Int32Array",
                    value: Array.prototype.slice.call(value),
                };
            }
            return value;
        });
    }
    return data;
}
function parseWebview(obj, list) {
    var newObj = {};
    if (typeof obj === "object") {
        if (obj.type) {
            switch (obj.type) {
                case "ArrayBuffer":
                    newObj = new Uint8Array(typeof obj.value === "object" ? obj.value : JSON.parse(obj.value)).buffer;
                    list === null || list === void 0 ? void 0 : list.push(newObj);
                    return newObj;
                case "Uint8Array":
                    newObj = new Uint8Array(typeof obj.value === "object" ? obj.value : JSON.parse(obj.value));
                    list === null || list === void 0 ? void 0 : list.push(newObj);
                    return newObj;
                case "Int8Array":
                    newObj = new Int8Array(typeof obj.value === "object" ? obj.value : JSON.parse(obj.value));
                    list === null || list === void 0 ? void 0 : list.push(newObj);
                    return newObj;
                case "Int16Array":
                    newObj = new Int16Array(typeof obj.value === "object" ? obj.value : JSON.parse(obj.value));
                    list === null || list === void 0 ? void 0 : list.push(newObj);
                    return newObj;
                case "Int32Array":
                    newObj = new Int32Array(typeof obj.value === "object" ? obj.value : JSON.parse(obj.value));
                    list === null || list === void 0 ? void 0 : list.push(newObj);
                    return newObj;
                default:
                    Object.keys(obj).forEach(function (item) {
                        newObj[item] = parseWebview(obj[item], list);
                    });
                    break;
            }
        }
        else if (obj instanceof Array) {
            return obj;
        }
        else {
            Object.keys(obj).forEach(function (item) {
                newObj[item] = parseWebview(obj[item], list);
            });
        }
    }
    else {
        return obj;
    }
    return newObj;
}


/***/ })
/******/ ]);
/************************************************************************/
/******/ 
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__[1]();
/******/ window.UniWorker = __webpack_exports__;
/******/ 
